<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/7/17 0017
 * Time: 下午 4:58
 */

namespace app\api\controller;


use think\Db;

class Zhaobiao extends Authinfo
{
    //数据列表页 全部数据
    public function zhaobiaolist(){
        //分页和排序
        $current=input('current');
        if(!$current){
            $current=1;
        }
        $pagenums=input('pagenums');
        if(!$pagenums){
            $pagenums=50;
        }
        $nowpagenums=($current-1)*$pagenums;
        $order=input('order');
        if(!$order){
            $order='hb_zhaobiaogs.id DESC';
        }
        // 总数
        $total=Db::table('hb_zhaobiaogs')->count('id');
        //所有数据
        $info=Db::name('zhaobiaogs')
            ->field('id,xmid,xmname,gongsi_created,townsid')
            ->order($order)
            ->limit($nowpagenums,$pagenums)
            ->select();
        if($info){
            // 循环每条数据获取村镇信息及其讲时间转换成时间错存进数据库
            foreach ($info as $key => $value) {
                $info[$key]['tname']=get_alltowns($value['townsid']);
                $info[$key]['gongsi_created']=time_nianyueri($value['gongsi_created']);

            }
            $datas['status']=1;
            $datas['total']=$total;
            $datas['info']=$info;
            $datas['current']=$current;

        }else{
            $datas['status']=0;
            $datas['total']=$total;
            $datas['info']='没有数据';
            $datas['current']=$current;
        }
        return json($datas);
    }
    // 点击列表后显示相信的一条数据
    public function view(){
        // 接受点击传过来的id
        $id=input('id');
        // 根据相关联的字段连四张表查询hb_zhaobiaogs hb_zhaobiaochanquan hb_zhaobiaoquansu hb_member
        $data=Db::table('hb_zhaobiaogs')
            ->field('hb_zhaobiaogs.*,hb_zhaobiaochanquan.*,hb_zhaobiaoquansu.*,hb_zhaobiaogs.id')
            ->join('hb_zhaobiaochanquan','hb_zhaobiaogs.id=hb_zhaobiaochanquan.gsid')
            ->join('hb_zhaobiaoquansu','hb_zhaobiaogs.id=hb_zhaobiaoquansu.quansuid')
            ->where(['hb_zhaobiaogs.id'=>$id])
            ->find();

        if($data){
            $datas['status'] = 1;
            $datas['info'] = $data;
        }else{
            $datas['status'] = 0;
            $datas['info'] = '无数据';
        }
        return json($datas);
    }

}